package rsj.api.test.offline;

import com.rlyy.aibase.utils.base.Box;
import common.util.BoxUtil;
import common.util.validator.ParameterConversionCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.test.entity.AddTestDataParam;
import rsj.db.dbutils.UniqueID;
import rsj.sql.test.MyCompanyTestDao;

import java.sql.SQLException;

/**
 * 测试数据录入
 *
 * @author yuanqinglong
 * @since 2021/3/4 15:10
 */
@RestController
public class AddTestDataController {

    Logger logger = LoggerFactory.getLogger(AddTestDataController.class);

    @Autowired
    private MyCompanyTestDao myCompanyTestDao;


    /**
     * 测试数据录入
     *
     * @param box 参数
     * @return 结果
     */
    @RequestMapping(name = "rsj_add_test_data")
    public Box executeLink(Box box) throws SQLException {
        // 参数转换和校验
        AddTestDataParam addTestDataParam = ParameterConversionCheck.parameterConversionCheckFastFail(box, AddTestDataParam.class);
        addTestDataParam.setLogId(String.valueOf(UniqueID.generateId()));
        myCompanyTestDao.addTestData(addTestDataParam);
        return BoxUtil.successBox(box);
    }


    ///**
    // * 添加测试数据
    // *
    // * @param addTestData 数据
    // */
    //private void addTestData(AddTestDataParam addTestData) throws SQLException {
    //    String sql = "INSERT INTO sys.sys_test_log (log_id, log_org_name, log_prod_id, log_prod_name, log_amount, log_time, log_type) " +
    //            "VALUES ('%s','%s','%s','%s','%s','%s','%s')";
    //    sql = String.format(sql, UniqueID.generateId(), addTestData.getLogOrgName(), addTestData.getLogProdId(), addTestData.getLogProdName(), addTestData.getLogAmount(), addTestData.getLogTime(), addTestData.getLogType());
    //    IExecuteInterface.doExecuteUpdate(sql, e -> logger.error("添加测试数据异常，{}", e));
    //}
}
